package com.zhouyu;

import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author leimingchao
 * create 2025-05-02 21:35
 *
 * 底层使用ASM技术
 */
public class Test3 {

	public static void main(String[] args) throws IOException {

		SimpleMetadataReaderFactory simpleMetadataReaderFactory = new SimpleMetadataReaderFactory();

		//构造一个MetadataReader
		MetadataReader metadataReader = simpleMetadataReaderFactory.getMetadataReader("com.zhouyu.service.UserService");

		//得到一个ClassMetadata，并获取类名
		ClassMetadata classMetadata = metadataReader.getClassMetadata();

		System.out.println(classMetadata.getClassName());
		//System.out.println(classMetadata.getInterfaceNames());
		////获取内部类名字
		//System.out.println(classMetadata.getMemberClassNames()[0]);


		//获取一个AnnotationMetadata，并获取类上的注解信息
		AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();

		//获取类上注解的元注解信息
		System.out.println(annotationMetadata.hasMetaAnnotation(Component.class.getName()));

		//获取类上注解的信息
		System.out.println(annotationMetadata.hasAnnotation(Component.class.getName()));

		for (String annotationType : annotationMetadata.getAnnotationTypes()) {

			System.out.println(annotationType);
		}

	}
}
